package org.coody.gitee.fuzzer;

import org.coody.gitee.entity.GiteeEntity;
import org.coody.gitee.exception.FuzzerException;
import org.coody.gitee.exception.VerCodeException;
import org.coody.gitee.fuzzer.iface.GiteeFuzzer;
import org.coody.gitee.handle.VerCodeHandle;
import org.coody.gitee.util.HttpUtil;
import org.coody.gitee.util.HttpUtil.HttpEntity;
import org.coody.gitee.util.StringUtil;

public class GiteeImgCodeFuzzer extends GiteeFuzzer{

	@Override
	public void fuzzer(GiteeEntity giteeEntity) throws FuzzerException {
		HttpEntity httpEntity = HttpUtil.Get("https://gitee.com/captcha?action=captcha&i=" + System.currentTimeMillis(),
				"utf-8", giteeEntity.getCookie(),30);
		giteeEntity.setCookie(httpEntity.getCookie());
		String code = VerCodeHandle.parseVercode(httpEntity.getBye());
		if(StringUtil.isNullOrEmpty(code)) {
			throw new VerCodeException("图片验证码解析失败>>"+giteeEntity.getAccount());
		}
		giteeEntity.setImgCode(code);
		System.out.println("图形验证码:"+giteeEntity.getEmail()+":"+giteeEntity.getImgCode());
	}

}
